package cn.signalpha.modules.social.service;

import cn.signalpha.core.mp.service.impl.ExtendServiceImpl;
import cn.signalpha.core.tool.utils.BeanUtil;
import cn.signalpha.modules.social.entity.Fans;
import cn.signalpha.modules.social.excel.FansExcel;
import cn.signalpha.modules.social.mapper.FansMapper;
import cn.signalpha.modules.social.vo.FansVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class FansService extends ExtendServiceImpl<FansMapper, Fans> {

	/**
	 * 自定义分页
	 */
    public IPage<FansVO> selectFansPage(IPage<FansVO> page, Map<String, Object> params) {
        return page.setRecords(baseMapper.selectFansPage(page, params));
    }

    /**
	 * 自定义导出
	 */
    public List<FansExcel> selectFansExcel(Map<String, Object> params) {
        return BeanUtil.copy(baseMapper.selectFansPage(null, params), FansExcel.class);
    }

	/**
	 * 查询
	 */
	public Fans getByUserIdAndFansId(Long userId, Long fansId) {
		return baseMapper.selectOne(Wrappers.<Fans>lambdaQuery().eq(Fans::getUserId, userId).eq(Fans::getFansId, fansId));
	}

	/**
	 * 是否关注
	 */
	public Long isFans(Long userId, Long fansId) {
		return count(Wrappers.<Fans>lambdaQuery().eq(Fans::getUserId, userId).eq(Fans::getFansId, fansId));
	}

	/**
	 * 获取我的关注用户id
	 */
	public List<Long> getUserIds(Long userId) {
		return list(Wrappers.<Fans>lambdaQuery().eq(Fans::getFansId, userId)).stream().map(Fans::getUserId).collect(Collectors.toList());
	}


}

